package models

import (
	"fmt"
	"qld2devservice/utils"
	"strconv"
)

type QldAmountPrice struct {
	Id         int `gorm:"primary_key"`
	Name       string
	PriceStr   string
	Type       int64
	OutletType int64
	AddBy      string
	Des        string
}
type PriceStr struct {
	PriceType int64
}

func GetQldAmountPriceById(id int64) (QldAmountPrice, error) {
	var qldAmountPrices []QldAmountPrice
	//条件查询
	err := DB.Where("id = ?", id).Find(&qldAmountPrices).Error
	if err != nil {
		newErr := utils.WrapError(err, "GetQldOutletPriceById:1,数据库获取设备价格失败,price_id="+strconv.FormatInt(id, 10))
		utils.MyPrint(utils.PRINT_ERROR, newErr.Error())
		return QldAmountPrice{}, newErr
	} else if len(qldAmountPrices) == 0 {
		newErr := utils.NewError(utils.ErrorTypeStop, "GetQldOutletPriceById:2,数据库获取设备价格未获取到,id="+strconv.FormatInt(id, 10))
		utils.MyPrint(utils.PRINT_ERROR, newErr.Error())
		return QldAmountPrice{}, newErr
	} else if len(qldAmountPrices) > 1 {
		newErr := utils.WrapError(err, "GetQldOutletPriceById:3,数据库获取设备价格获取到多个,"+fmt.Sprintf("%+v", qldAmountPrices))
		utils.MyPrint(utils.PRINT_ERROR, newErr.Error())
		return qldAmountPrices[0], newErr
	}
	return qldAmountPrices[0], nil
}
